package com.cskaoyan.controller;

import com.cskaoyan.bean.data.OrderDetailData;
import com.cskaoyan.bean.vo.AftersaleVo;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.AfterSaleService;
import com.cskaoyan.service.OrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("wx/aftersale")
public class WxAftersaleController {
    @Autowired
    AfterSaleService afterSaleService;
    @Autowired
    OrderService orderService;

    @PostMapping("submit")
    public BaseRespVo submit(@RequestBody AftersaleVo aftersaleVo) {
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated()) {
            Integer userId = (Integer) subject.getPrincipal();
            int result = afterSaleService.applyAfterSale(userId, aftersaleVo);
            if (result == 1) {
                return BaseRespVo.ok(null);
            } else {
                return BaseRespVo.msg("申请售后失败");
            }
        }
        return BaseRespVo.unAuthc();
    }

    //orderId=？
    @GetMapping("detail")
    public BaseRespVo detail(Integer orderId) {
        Map<String, Object> detail = afterSaleService.detail(orderId);
        return BaseRespVo.ok(detail);
    }
}
